<?php
/* post type for testimonials */
$labels = array(
    'name'                  => _x('Testimonials', 'post type general name', 'dt'),
    'singular_name'         => _x('Testimonials', 'post type singular name', 'dt'),
    'add_new'               => _x('Add New', 'post type new', 'dt'),
    'add_new_item'          => __('Add New Testimonial', 'dt'),
    'edit_item'             => __('Edit', 'dt'),
    'new_item'              => __('New Testimonial', 'dt'),
    'view_item'             => __('View', 'dt'),
    'search_items'          => __('Search', 'dt'),
    'not_found'             =>  __('No Testimonials Found', 'dt'),
    'not_found_in_trash'    => __('No Testimonials Found in Trash', 'dt'), 
    'parent_item_colon'     => '',
    'menu_name'             => 'Testimonials'
);

$img = get_template_directory_uri(). '/images/admin_ico_testimonials.png';

$args = array(
    'labels'                => $labels,
    'public'                => false,
    'publicly_queryable'    => false,
    'show_ui'               => true, 
    'show_in_menu'          => true, 
    'query_var'             => true,
    'rewrite'               => false,
    'capability_type'       => 'post',
    'has_archive'           => false, 
    'hierarchical'          => false,
    'menu_position'         => 31,
    'menu_icon'		        => $img,
    'supports'              => array( 'title', 'editor', 'author' )
); 
register_post_type( 'dt_testimonials', $args );
			
			// metaboxez
			// WP 3.0+
//			add_action( 'add_meta_boxes', 'dt_gallery_box' );
			
			// backwards compatible
			//add_action( 'admin_init', 'dt_gallery_box', 1 );

			/* Do something with the data entered */
//			add_action( 'save_post', 'dt_gallery_list_save' );

/*			function dt_gallery_box() {
				if ( isset($_GET['post']) ) {
					$post_id = $_GET['post'];
				} elseif ( isset($_POST['post_ID']) ) {
					$post_id = $_POST['post_ID'];
				} else
					return;

				$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
 
				// check for a template type
				if ( ($template_file == 'gallery.php') || ($template_file == 'photos.php') ) {
					add_meta_box(	'gallery-list',
									__( 'Gallery options', 'dt' ),
									'dt_gallery_list_box',
									'page',
									'side',
									'high'
								);
				}
			}
			
			function dt_gallery_list_box( $post ) {
				echo '<script>var dt_admin = {box: "#gallery-list"};</script>';
				echo '<script src="' . get_template_directory_uri() . '/js/admin_gallery.js"></script>';
				// Use nonce for verification
				wp_nonce_field( plugin_basename( __FILE__ ), 'gallery_nonce' );
				$all_ids = array();
				$query = new Wp_Query( 'post_type=dt_gallery&posts_per_page=-1' );
				$posts = $query->posts;
				$filter = get_post_meta( $post->ID, 'galery_filter', true );
				$number_portf = ( isset($filter['posts_per_page']) && $filter['posts_per_page'] )?$filter['posts_per_page']:'';
				if(isset($filter['only']) && is_array($filter['only']) ) $only = $filter['only']; else $only = array();
				if(isset($filter['except']) && is_array($filter['except']) ) $except = $filter['except']; else $except = array();
				if( empty($only) && empty($except) ) $all = ' checked="checked"'; else $all ='';
				echo '<p>' . __( 'Show Albums:', 'dt' ) . '<br></p>';
				echo '<div class="showhide"><label><input name="show_type_gal" value="all"' . $all . ' type="radio">' . __( 'All', 'dt' ) . '</label><br></div>';
				echo '<div class="showhide"><label><input name="show_type_gal" value="only"' . (empty($only)?'':' checked="checked"') . ' type="radio">' . __( 'Only...', 'dt' ) . '</label><br>';
					echo '<div style="margin-left: 20px; margin-bottom: 8px; display: none;" class="list">';
						if( $posts ){
							foreach( $posts as $post ){
								$all_ids[] = $post->ID;
								echo '<label><input name="show_gal[only][]" value="' . $post->ID . '" type="checkbox"' . (in_array($post->ID, $only)?' checked':'') . '>' . $post->post_title . '</label><br>';
							}
						}
					echo '</div>';
				echo '</div>';
				echo 	'<div class="showhide"><label><input name="show_type_gal" value="except"' . (empty($except)?'':' checked="checked"') . ' type="radio">' . __( 'Except...', 'dt' ) . '</label><br>
						<div style="margin-left: 20px; margin-bottom: 8px; display: none;" class="list">';
						if( $posts ){
							foreach( $posts as $post ){
								echo '<label><input name="show_gal[except][]" value="' . $post->ID . '" type="checkbox"' . (in_array($post->ID, $except)?' checked':'') . '>' . $post->post_title . '</label><br>';
							}
						}
					echo '</div>';
				echo '</div>';
				echo '<input type="hidden" name="show_gal[all]" value="'. serialize( $all_ids ). '"/>';
				echo '<p>';
				echo '<input type="text" id="dt_gallery_postsonpage" size="4" name="number_portf" value="'. $number_portf. '"/>';
				echo '<label for="dt_gallery_postsonpage">'. __( 'Number of posts on this page( if empty - uses standard setting )', LANGUAGE_ZONE ). '</label>';
				echo '</p>';
			}
			
			function dt_gallery_list_save( $post_id ) {
				// verify if this is an auto save routine. 
				// If it is our form has not been submitted, so we dont want to do anything
			  
				if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
					return;

				// verify this came from the our screen and with proper authorization,
				// because save_post can be triggered at other times

				if ( !isset( $_POST['gallery_nonce'] ) || !wp_verify_nonce( $_POST['gallery_nonce'], plugin_basename( __FILE__ ) ) )
					return;

			  
				// Check permissions
				if ( !current_user_can( 'edit_page', $post_id ) )
				return;
				
				$mydata = null;
				switch( $_POST['show_type_gal'] ) {
					case 'only':
						if( isset($_POST['show_gal']['only']) ) {
							$mydata['only'] = $_POST['show_gal']['only'];
						}
						break;
					case 'except':
						if( isset($_POST['show_gal']['except']) ) {
							$mydata['except'] = $_POST['show_gal']['except'];
						}
					default:
						if( isset($_POST['show_gal']['all']) ) {
							$mydata['all'] = unserialize( $_POST['show_gal']['all'] );
						}
				}
				
				$mydata['posts_per_page'] = intval($_POST['number_portf']);
				
				update_post_meta( $post_id, 'galery_filter', $mydata );
			}
*/